﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using BlackBird.Models;
using BlackBird.DataAccess;

namespace BlackBird.Repositories
{
    public class UserRepository
    {
        public ICollection<UserDM> AllUsers
        {
            get{ return MockupDataStore.GetAllUsers(); }
        }

        public bool ValidateUser(string userName, string password)
        {
            return AllUsers.Any(u => u.Name == userName && u.Password == password);
        }

        public string[] GetRolesInString(string userName)
        {
            RoleType[] roles = GetRoles(userName);
            List<string> roleStringList = new List<string>();

            foreach (var p in roles)
                roleStringList.Add(p.ToString());

            return roleStringList.ToArray();
        }

        public RoleType[] GetRoles(string userName)
        {
            return AllUsers.Where(u => u.Name == userName)
                .Select(u => u.Roles)
                .FirstOrDefault();
        }

        public UserDM GetByNameAndPassword(string name, string password)
        {
            return AllUsers.FirstOrDefault(u => u.Name == name && u.Password == password);
        }
    }
}